const DButil = require('./DButil');

// 添加教师信息,密码默认6个1
function insertTeacher(taccount, tpwd, tname, classid, success, fail){
    let connection = DButil.createConnection();
    connection.connect();
    let sql = 'insert into teacher(taccount, tpwd, tname, cid) value(?,?,?,?);'
    let params = [taccount, tpwd, tname, classid];
    connection.query(sql, params, (err, result) => {
        if (err) {
            console.log(err);
            fail();
        }else{
            success(result);
        }
    })
    connection.end();
}

// 教师登录功能
function teacherLogin(taccount, tpwd, success, fail){
    let connection = DButil.createConnection();
    connection.connect();
    let sql = 'select * from teacher where taccount=? and tpwd=?;';
    let params = [taccount, tpwd];
    connection.query(sql, params, (err, result) => {
        if (err) {
            fail(err);
        }else{
            success(result);
        }
    })
    connection.end();
}

module.exports.insertTeacher = insertTeacher;
module.exports.teacherLogin = teacherLogin;